/*
 *
 *  * Copyright (c) 2016. For Intelligent Group.
 *
 */

package com.intelligent.ispc.common.utils;

import java.text.MessageFormat;
import java.util.ResourceBundle;

/**
 * Created by Peter on 2016/7/26.
 */
public class ResourceBundleUtils {

    private static final String RES_NAME = "i18n.i18n";
    //    private final static Locale locale = new Locale("en", "US");
    private static final ResourceBundle RESB = ResourceBundle.getBundle(RES_NAME);

    /**
     * Get the i18n resource with key.
     *
     * @param key property key
     * @return property value
     */
    public static String getString(String key) {
        try {
            return RESB.getString(key);
        } catch (Exception e) {
            return key;
        }
    }

    /**
     * Get the i18n resource with key and params, format "Hello world {0}" with param[0]
     *
     * @param key property key
     * @param params params with key
     * @return property value
     */
    public static String getString(String key, Object[] params) {
        try {
            String result = RESB.getString(key);
            return MessageFormat.format(result, params);
        } catch (Exception e) {
            return key;
        }
    }
}
